package com.deer.wms.base.system.web;

import com.deer.wms.base.system.model.PageSet.PageSet;
import com.deer.wms.base.system.model.PageSet.PageSetCriteria;
import com.deer.wms.base.system.model.PageSet.PageSetDto;
import com.deer.wms.base.system.service.PageSetService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by guo on 2019/11/27.
*/
@Api(description = "页面显示api接口")
@RestController
@RequestMapping("/page/sets")
public class PageSetController {

    @Autowired
    private PageSetService pageSetService;

    @PostMapping("/insert")
    public Result add(@RequestBody PageSet pageSet) {
        pageSetService.save(pageSet);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        pageSetService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody PageSet pageSet) {
        pageSetService.updateById(pageSet);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(@PathVariable Integer id) {
        PageSet pageSet = pageSetService.getById(id);
        return ResultGenerator.genSuccessResult(pageSet);
    }


    @GetMapping("/list")
    public Result list(PageSetCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<PageSetDto> list = pageSetService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
